<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>{{ i18n('squad.view') }}</div>
        </div>

        <div class="admin_main_block_right">
          <div>
            <el-button icon="Back" @click="router.go(-1)">
              {{ i18n('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_form_main">
        <el-form label-width="120px" ref="formRef" :model="dataForm" :rules="dataRule">
          <el-card class="box-card" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('common.basic_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-row>
                <el-col :span="4">
                  <el-image :src="dataForm.picture"></el-image>
                </el-col>
                <el-col :span="20">
                  <el-descriptions border>
                    <el-descriptions-item width="200" :label="i18n('squad.squad_no')" label-align="right" :span="3">
                      <div v-html="dataForm.squad_no"></div>
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('squad.title')" label-align="right" :span="3">
                      <div v-html="dataForm.title"></div>
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('course.title')" label-align="right" :span="3">
                      <div v-html="dataForm.course_title"></div>
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('squad.teacher_name')" label-align="right" :span="3">
                      <div v-html="dataForm.teacher_name"></div>
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('squad.total')" label-align="right" :span="3">
                      <div v-html="dataForm.total"></div>
                    </el-descriptions-item>

                    <!-- 第五行 -->
                    <el-descriptions-item width="200" :label="i18n('squad.start_time')" label-align="right">
                      <div v-html="dataForm.start_time"></div>
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('squad.end_time')" label-align="right">
                      <div v-html="dataForm.end_time"></div>
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('squad.open_status')" label-align="right">
                      <div v-html="dataForm.open_status.text"></div>
                    </el-descriptions-item>

                    <!-- 第六行 -->
                    <el-descriptions-item width="200" :label="i18n('common.create_time')" label-align="right">
                      <div v-html="dataForm.create_time"></div>
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('common.status')" label-align="right" :span="2">
                      <div v-html="dataForm.status.text"></div>
                    </el-descriptions-item>
                  </el-descriptions>
                </el-col>
              </el-row>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('common.detail_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border>
                <el-descriptions-item width="200" :label="i18n('squad.content')" label-align="right" :span="3">
                  <div v-html="dataForm.content"></div>
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('squad.organization_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-row>
                <el-col :span="4">
                  <el-image :src="dataForm.organization.logo"></el-image>
                </el-col>
                <el-col :span="20">
                  <el-descriptions border>
                    <el-descriptions-item width="200" :label="i18n('organization.organization_no')" label-align="right" :span="3">
                      {{ dataForm.organization.organization_no }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.title')" label-align="right" :span="3">
                      {{ dataForm.organization.title }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('organization.create_time')" label-align="right" :span="3">
                      {{ dataForm.organization.create_time }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('common.status')" label-align="right" :span="3">
                      {{ dataForm.organization.status.text }}
                    </el-descriptions-item>
                  </el-descriptions>
                </el-col>
              </el-row>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('common.audit_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border>
                <el-descriptions-item width="200" :label="i18n('common.audit_status')" label-align="right" :span="3">
                  {{ dataForm.audit_status.text }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('squad.audit.content')" label-align="right" :span="3">
                  {{ dataForm.audit_content }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script setup name="squad-view">
  import { useBase } from "@/hooks/base/useBase"
  import { useForm } from "@/hooks/form/useForm"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('squad')
  const dataForm = reactive({
    id: 0,
    organization_id: 0,
    teacher_id: 0,
    squad_no: '',
    picture: '',
    title: '',
    teacher_name: '',
    total: '',
    start_time: '',
    end_time: '',
    content: '',
    create_time: '',
    open_status: '',
    status: '',
    course_title: '',
    audit_status: '',
    audit_content: '',
    organization: {
      logo: '',
      organization_no: '',
      title: '',
      create_time: '',
      status: [],
    }
  })

  const dataRule = reactive({})

  const {
    formRef
  } = useForm(model.value, dataForm)

  const init = (form) => {
    dataForm.id = query.id || 0

    nextTick(() => {
      form.value.resetFields()
      if (dataForm.id) {
        $http({
          url: $http.adornUrl(`/squad/view/${dataForm.id}`),
          method: 'get',
          params: $http.adornParams({}),
        }).then(({ data }) => {
          if (data && data.status === 200) {
            dataForm.organization_id = data.data.organization_id
            dataForm.teacher_id = data.data.teacher_id
            dataForm.squad_no = data.data.squad_no
            dataForm.picture = data.data.picture
            dataForm.title = data.data.title
            dataForm.total = data.data.total
            dataForm.start_time = data.data.start_time
            dataForm.end_time = data.data.end_time
            dataForm.open_status = data.data.open_status
            dataForm.audit_status = data.data.audit_status
            dataForm.status = data.data.status
            dataForm.create_time = data.data.create_time
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/detail/data`),
              method: 'get',
              params: $http.adornParams({
                'squad_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                if(data.data) {
                  dataForm.content = data.data.content
                }
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/organization/data`),
              method: 'get',
              params: $http.adornParams({
                'id': dataForm.organization_id
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                if(data.data) {
                  dataForm.organization = data.data
                }
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/member/data`),
              method: 'get',
              params: $http.adornParams({
                'id': dataForm.teacher_id
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                if(data.data) {
                  dataForm.teacher_name = data.data.nickname
                }
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/audit/data`),
              method: 'get',
              params: $http.adornParams({
                'squad_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                if(data.data) {
                  dataForm.audit_content = data.data.content
                }
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/course/data`),
              method: 'get',
              params: $http.adornParams({
                'squad_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                if(data.data && data.data.course) {
                  dataForm.course_title = data.data.course.title
                }
              }
            })
          }
        })
      }
    })
  }

  onMounted(() => {
    init(formRef)
  })
</script>

<style lang="scss" scoped>
  .el-image {
    padding: 0 5px;
    max-width: 260px;
    max-height: 260px;
    width: 100%;
    height: 260px;
  }
</style>
